package com.zhentao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhentao.pojo.CarModel;
import com.zhentao.vo.CarModelVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;

/**
* @description 车型管理Mapper接口
*/
@Mapper
public interface CarModelMapper extends BaseMapper<CarModel> {
    
    /**
     * 关联查询车型和品牌信息
     */
    @Select("SELECT m.*, b.brand_name, b.brand_code, b.logo_url as brand_logo_url, b.country as brand_country " +
            "FROM car_model m " +
            "LEFT JOIN car_brand b ON m.brand_id = b.id " +
            "WHERE m.id = #{id}")
    CarModelVO getModelWithBrand(Long id);
    
    /**
     * 分页关联查询车型和品牌信息
     */
    @Select("SELECT m.*, b.brand_name, b.brand_code, b.logo_url as brand_logo_url, b.country as brand_country " +
            "FROM car_model m " +
            "LEFT JOIN car_brand b ON m.brand_id = b.id " +
            "WHERE m.status = 1")
    IPage<CarModelVO> pageModelWithBrand(Page<CarModel> page);
    
    /**
     * 根据品牌ID查询车型列表
     */
    @Select("SELECT m.*, b.brand_name, b.brand_code, b.logo_url as brand_logo_url, b.country as brand_country " +
            "FROM car_model m " +
            "LEFT JOIN car_brand b ON m.brand_id = b.id " +
            "WHERE m.brand_id = #{brandId} AND m.status = 1")
    List<CarModelVO> listModelsByBrandId(Long brandId);
}
